let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    height:200,
    scrollTop:0,
    selList:[],
    list:[],
    keyword:"",
    page:1,
    limit:16,
    total:0
  },

  //搜索操作
  searachClick:function(){
      var keyword = this.data.keyword;
      var selList = this.data.selList;
      this.setData({
        list:[],page:1,total:0
      });
      this.ListApi();
  },

  //获取政策列表
  ListApi:function(){
    var that = this;
    var keyword = this.data.keyword;
    var selList = JSON.stringify(this.data.selList);
    var page = this.data.page;
    var limit = this.data.limit;
    var params = {keyword:keyword,selList:selList,page:page,limit:limit};
    //获取项目列表
    app.request('post', '/api/Policy/ListApi', params).then(res => {

      let list = that.data.list;
      res.data.list.forEach(item => {
        list.push(item);
      });

      that.setData({
        count: res.data.count,
        list: list,
        total: res.data.total,
      });
    }).catch(err => console.log(err));

  },


  //跳转详情页面
  policyView:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({ url: `/pages/policy/policyView?id=${id}` })
  },

  //滚动到底部
  scrollBottom:function(){
      var page = this.data.page;
      var total = this.data.total;
      if(page<total){
        this.setData({page:page+1});
        this.ListApi();
      }
  },

  //输入关键字
  keywordClick: function (e) {
    this.setData({
      keyword: e.detail.value
    });
  },

//删除单个条件
delOption:function(e){
  var selList = this.data.selList;
  var val =  e.currentTarget.dataset.index;
  for (var i = 0; i < selList.length; i++) {
    if (i == val) {
      selList.splice(i, 1);
    }
  }
  this.setData({ selList:selList});
  this.searachClick();
},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
     

      var keyword = "";
      var selList = [];
      if(options.keyword!=undefined){
           keyword = options.keyword;
      }
      if(options.selList!=undefined){
         selList = JSON.parse(options.selList);
      }
      this.setData({
        keyword:keyword,
        selList:selList
      });
      
      this.ListApi();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    let that = this;
    var query = wx.createSelectorQuery();
    query.select('.selCondition').boundingClientRect()
    query.exec(function(res) {
      console.log(res[0].height);
        //res就是 所有标签为mjltest的元素的信息 的数组
        let topHeight = res[0].height+103+60;
         // 获取系统信息
        wx.getSystemInfo({
          success: function (res) {
              // 获取可使用窗口宽度
              let clientHeight = res.windowHeight;
              that.setData({
                height:clientHeight-topHeight
              })
          }
        });
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})